JavaScript中的单选按钮

时间:2019-07-07 16:15:03

标签: php radio-button

我从使用ajax调用的下拉菜单中获得了此单选按钮结果。但是我没有从单击的单选按钮返回任何结果。这个脚本有什么问题?

<script>
....................
var sScript="<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"><\/script>";
sScript = sScript + "<script defer>";
sScript = sScript + "$("input[type='radio']").click(function(){ var radioValue = $("input[name='choose']:checked").val(); if(radioValue){ $('#radioresult').val($("input[type='radio']:checked").val()); console.log(radioValue) } });";
sScript = sScript + "</script>";

var htmlss= '<div class="ajxstyle"><table border="1"><thead><tr><th>Radio</th><th>Shipping Name</th><th>Shipping Fee</th><th>Shipping Time</th></tr></thead><tbody>';
    htmlss += '<tr>';
    htmlss += '<td><input type="radio" name="choose"  value="'+value.shipping_fee+'" onclick"funsio();"></td>';
    htmlss += '<td>'+value.shipping_name+'</td>';
    htmlss += '<td>'+value.shipping_fee+'</td>';
    htmlss += '<td>'+value.shipping_time+'</td>';
    htmlss += '</tr>';
    htmlss += '</tbody></table>';
    txtHint.innerHTML = htmlss + sScript;
</script>
<body>
<div id="txtHint"></div>
</body>

1 个答案:

答案 0 :(得分:0)

我通过将var sScript更改为

解决了该问题
           var s = document.createElement('script');
                s.type = 'text/javascript';
            var code = 'function check(browser){';
                code += 'document.getElementById("answer").value=browser;}';
            try {
                s.appendChild(document.createTextNode(code));
                document.body.appendChild(s);
            } catch (e) {
                s.text = code;
                document.body.appendChild(s);
            }

但是如何将值转换为HTML?