[英]JQuery Not Triggering On Button.click
I've written some code that should check a textbox (ID tfa_1) to see if its empty or contains text, this should trigger on a next page button (wfpagenextID6) being clicked. 我编写了一些代码,该代码应检查文本框(ID tfa_1)以查看其是否为空或包含文本,这应在单击下一页按钮(wfpagenextID6)时触发。
I've tried replacing my script with an alert("test.") and it dosent appear, so im assuming I have my trigger wrong but I cannot work out what I have done wrong! 我尝试用alert(“ test。”)替换我的脚本,并且它没有出现,所以即时通讯假设我的触发器错了,但是我无法确定我做错了什么!
My HTML that defines the textbox is below: 我定义文本框的HTML如下:
<input type="text" id="tfa_2685" name="tfa_2685" value="" placeholder="" title="Previous Surname (if applicable) " class="">
and the button is 并且按钮是
<input value="Next Page" type="button" class="wfPageNextButton" wfpageindex_activate="7" id="wfPageNextId6" style="visibility: visible;">
Both of these are generated and I cannot change them! 这两个都是生成的,我无法更改!
My Script is: 我的脚本是:
<script>
$(document).ready(function(){
$('#wfPageNextId6').click(function(){
var inp.Val= $("#tfa_2685").val();
if (inp.val().length > 0) {
alert("Test.");
}
});
})
</script>
if you want to assign value to inp variable, you should just do: var inp = $("#tfa_2685").val();
如果要将值分配给inp变量,则应该执行以下操作:
var inp = $("#tfa_2685").val();
And then call to inp.val()
just replace with inp
, for inp is not jQuery object so it doesn't have val() method 然后打电话给
inp.val()
只是更换inp
,对于INP是不是jQuery对象,因此不会有VAL()方法
An identifier ( variable ) must not contains dots. 标识符(变量)不得包含点。 ( see more details ECMAScript specification in section 7.6 Identifier Names and Identifiers )
(请参阅7.6标识符名称和标识符中的更多详细信息ECMAScript规范)
the next variable declaration is wrong 下一个变量声明错误
var inp.Val= $("#tfa_2685").val();
to fix this 解决这个问题
var inp = $("#tfa_2685");
You have syntax, try this: 您有语法,请尝试以下操作:
$(document).ready(function(){
$('#wfPageNextId6').click(function(){
var inpVal= $("#tfa_2685").val();
if (inpVal.length > 0) {
alert("Test.");
}
});
});
https://jsfiddle.net/cua40s80/ https://jsfiddle.net/cua40s80/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.