[英]javascript function only works on second click
i have a link that will call 3 js functions.我有一个将调用 3 个 js 函数的链接。 This is how i wrote the link :
这是我写链接的方式:
echo "<td>
<a href='javascript:void(0)'
onclick=$('#f').window('open');
$(window).scrollTop($('#f').offset().top-60);
checkForMatch();
data-id='$row[0]'data-integ='$row[1]'data-type='$row[2]'
class='edit_conn'
>Edit</a></td>";
the onclick=$('#f').window('open');
onclick=$('#f').window('open');
will open a modal and work just fine.将打开一个模态并正常工作。
the $(window).scrollTop($('#e').offset().top-60);
$(window).scrollTop($('#e').offset().top-60);
will reposition the modal and also work just fine.将重新定位模态并且也可以正常工作。
however the checkForMatch();
但是
checkForMatch();
only work on second click (this one will disable input based on textbox value)仅适用于第二次点击(这将禁用基于文本框值的输入)
Any clue why the checkForMatch();
任何线索为什么
checkForMatch();
function only work on second click ?功能只适用于第二次点击?
please pardon my potato english.请原谅我的土豆英语。
Edit :编辑 :
here is how i wrote the checkForMatch
function :这是我编写
checkForMatch
函数的方式:
function checkForMatch() {
var input1 = document.getElementById("typeconn_edit");
var input2 = document.getElementById("countryphone_edit");
if (input1.value == 'mobile_Phone') {
input2.disabled = true;
} else {
input2.disabled = false;
}
}
Edit2 : The "f" is a jqueryUI modal window this is how its written : Edit2:“f”是一个 jqueryUI 模态窗口,它是这样写的:
<div id="f" class="easyui-window formedit" title="Entry identity
Connectivity" data-options="modal:true,closed:true,iconCls:'icon-save'">
<?php include 'form_edit_conn.php'; ?>
</div>
the "idconn_edit", "integconn_edit", "typeconn_edit" are input textboxes “idconn_edit”、“integconn_edit”、“typeconn_edit”是输入文本框
<input type="text" id="idconn_edit" name="id">
<input type="text" id="integconn_edit" name="integ_conn">
<input type="text" id="typeconn_edit" name="type_conn">
and this is how i pass values to those 3 textboxes :这就是我将值传递给这 3 个文本框的方式:
(document).on("click", ".edit_conn", function () {
var id = $(this).data('id');
var type = $(this).data('type');
var integ = $(this).data('integ');
$(".formedit #idconn_edit").val( id );
$(".formedit #integconn_edit").val( integ );
$(".formedit #typeconn_edit").val( type );
});
and the "countryphone_edit" is a selectbox “countryphone_edit”是一个选择框
<select id="countryphone_edit">
<option value="0">Please Select</option>
<?php
$query = mysql_query("SELECT Country_Name FROM tbl_country");
while ($row = mysql_fetch_array($query)) {
?>
<option value="<?php echo $row['Country_Name']; ?>">
<?php echo $row['Country_Name']; ?>
</option>
<?php
}
?>
</select>
and sorry there's no 'e' i didnt realize that one since 'f' already on a good position.抱歉,没有 'e' 我没有意识到那个,因为 'f' 已经处于一个好的位置。
I solved it,我解决了,
i added checkForMatch();我添加了 checkForMatch(); function on the passing values code (edit_conn)
传递值代码的函数 (edit_conn)
(document).on("click", ".edit_conn", function () {
var id = $(this).data('id');
var type = $(this).data('type');
var integ = $(this).data('integ');
$(".formedit #idconn_edit").val( id );
$(".formedit #integconn_edit").val( integ );
$(".formedit #typeconn_edit").val( type );
checkForMatch();
});
i honestly dont understand why adding checkForMatch();
老实说,我不明白为什么要添加
checkForMatch();
there solved my problem, but i think thats enough.那里解决了我的问题,但我认为这就足够了。 Ty guys
泰哥们
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.