繁体   English   中英

使用经典ASP和jQuery中的Checkbox值填充文本框

[英]Populate Textbox with Checkbox Value in classic ASP and jQuery

这是我的代码片段:

 response.write "<th align=left><font size=2>"
    response.write "1. <input type=checkbox class='checkboxes' value='ORG'>Organization"
    response.write "</font> </th>"
    response.write "<th align=left><font size=2>"
    response.write "2. <input type=checkbox  value='OpType' class='checkboxes'>Operation Type"
    response.write "</font> </th>"
    response.write "<th align=left><font size=2>"
    response.write "3. <input type=checkbox checked  value='YEAR' class='checkboxes'>Year"
    response.write "</font> </th>"

response.write "<tr><td colspan='3'> <input name='DISTRIBUTION' size='45' /></td></tr>"

这是javascript。

<script type="text/javascript" src="../Scripts/jquery-1.9.1.js"></script>
$('.checkboxes').change(function () {
    alert("1");
    $("input[Title='DISTRIBUTION']").val("");
    if ($('.checkboxes').is(':checked')) {
        $("input[Title='DISTRIBUTION']").val("Yes");
    }
});

我没有看到警报,所以看起来它不会被解雇。 我做错什么了吗?

也许脚本是在文档完全构建之前执行的? 只是一个猜测,但尝试将你的jquery代码包装在其中;

$(document).ready(function () { ... });

您还应该研究KnockoutJs - 它会让您的生活更轻松......

我怀疑这只是在分配事件处理程序之前不等待DOM准备就绪的情况。 试试这个......

$(function() {
    $('.checkboxes').change(function () {
        alert("1");
        $("input[Title='DISTRIBUTION']").val("");
        if ($('.checkboxes').is(':checked')) {
            $("input[Title='DISTRIBUTION']").val("Yes");
        }
    });
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM