[英]Clearing text input with jquery
I have an input field: 我有一个输入字段:
<input name="test1" class="t-input" id="test1" style="color: #fff;" type="text" value="3.05"/
I am trying to change the value or clear the value through jquery, I've tried all of these and none of them are working. 我试图通过jquery更改值或清除值,我已经尝试了所有这些方法,但没有一个起作用。 The value changes, but I have to click on the textbox to see the change take effect.
值更改了,但是我必须单击文本框才能看到更改生效。 Am I missing something?
我想念什么吗?
$('#test1').val('');
$('#test1').val("");
$('#test1').val("").change();
$('#test1').val("").trigger('change');
$('#test1').attr(value,'');
Maybe you try to work with it when dom is not built yet, try to use ready
event handler: 也许在尚未建立dom的情况下尝试使用它,请尝试使用
ready
事件处理程序:
$(document).ready(function () {
// your code
});
You should wait your page to be fully loaded ( ready in jquery ) to update your field : 您应该等待页面完全加载(在jquery中准备好 )以更新字段:
<script type="text/javascript">
$(document).ready(function () {
$('#test1').val('');
});
</script>
if that's not working, you probably need to read your Error Console (ctrl + shift + j on Firefox). 如果这不起作用,则可能需要阅读错误控制台(在Firefox上为ctrl + shift + j)。
Try this: 尝试这个:
$("#test1").removeAttr("value")
This will do your job i guess. 我想这将做您的工作。
Ok Got it!! 好的,我知道了!!
It is a text box being rendered using telerik mvc controls. 它是使用telerik mvc控件呈现的文本框。 So this is how you clear it.
所以这就是您清除它的方式。
$('#text1').data("tTextBox").value(''); $( '#文本1')的数据( “tTextBox”)值( '')。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.