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

时间:2013-09-16 16:22:15

标签: javascript jquery asp-classic

这是我的代码片段:

 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");
    }
});

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

2 个答案:

答案 0 :(得分:2)

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

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

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

答案 1 :(得分:0)

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

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