如上图,是查看源码,命名checked选中了,为什么在dom节点上没有效果呢jQuery

解决方案 »

  1.   


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
    <title>无标题文档</title>
    </head><body>
    <input type="radio" name="a" checked="checked" value="1" />选我
    <input type="radio" name="a" value="1" />选Ta
    <script type="text/javascript">
    jQuery(function($){
    alert($(':radio:checked').val());
    });
    </script>
    </body>
    </html>
      

  2.   


    谢谢大大的回答,可是父页面上也没有value
      

  3.   

    没有value怎么知道哪个被选中了呀
      

  4.   

    如果是用脚本控制选中项的,要用prop,checked不行。
      

  5.   

    选中没效果,值没有传到iframe中?
      

  6.   


    // 在点击添加之前,存储已经添加好的题目ID
                        var toId = '';
                        if ($('.addTopic_list li').size() > 0) {
                            $('.addTopic_list li').each(function () {
                                toId += ',' + $(this).attr('rel');
                            })
                            toId = toId + ',';
                        }                    var topics = '';
                        var operate = "<p class='operate'><label class='lc'>操作:</label><label style='cursor: pointer' class='com editTopic'>编辑</label><label style='cursor: pointer' class='delTopic'>删除</label></p>";                     // 获取题目内容前,要对比下该题目的ID是否在已添加的题目列表里,在就不用添加
                        $(window.parent.document).find('.topicOption p span.selected').each(function() {
                            var tmp = ',' + $(this).parent().parent().attr('rel') + ',';
                            if (toId.indexOf(tmp) == -1) {                            // 标题
                                var title = $(this).parent().siblings().find('.ttitle').text();                            // 内容
                                var content = $(this).parent().siblings().find('.tcontent').text();                            // 答案
                                var answer = $(this).parent().parent().attr('attr') == 3 ? '<ul class="dalist1">' + $(this).parent().siblings().find('.tanswer').html() + '</ul>' : $(this).parent().siblings().find('.tanswer').html();
                                topics += "<li rel='" + $(this).parent().parent().attr('rel') + "' attr='" + $(this).parent().parent().attr('attr') + "'><div class='ttitle'>" + title + "</div><div class='tcontent'>" + content + "</div><div class='tanswer'>" + answer + "</div>" + operate + "</li>";
                                answerObject[$(this).parent().parent().attr('rel')] = {
                                    dbStatus: 2,
                                    to_type: $(this).parent().parent().attr('attr'),
                                    to_answer: getAnswer($(this).parent().next().find('.tanswer'), $(this).parent().parent().attr('attr')),
                                    to_option: getOption($(this).parent().next().find('.tanswer'), $(this).parent().parent().attr('attr')),
                                    to_title: $(this).parent().next().find('.tcontent').text()
                                };
                            }                        
                        })                    // 把选中的节点追加到addTopic_list后面
                        $('.addedTopic_box .addTopic_list').append(topics);
      

  7.   

    我是直接把那块代码html()直接获得的
      

  8.   

    在哪负责创建input type="radio"
      

  9.   


        // 单选题
        function syncSingle(i, num, answer) {
            var num = num.split(',');
            var html = '';
            var answer = eval('(' + answer + ')');
            for (var j = 0; j < num.length; j++) {
                html += '<input value="' + j + '" type="radio" name="single' + i + '"';
                if (j == parseInt(answer)) {
                    html += 'checked="checked"';
                }
                html += '><label class="option" style="cursor: pointer;">' + infor(j) + '</label>';
            }        return html;
        }
      

  10.   

    哪现在标注radio选中的回答对不对呀,我的意思是如果答案是1,value=1的radio有没有checked属性呀另外,单选就一个答案,为什么要用eval呀?
      

  11.   

    答案都存成json格式了,数据库里这种形式的["1"]
      

  12.   

    syncSingle的返回值怎么添加到容器里面的,发来看下
      

  13.   


        // 单击搜索功能
        function getSearchResult(p) {         var obj = {};        // 获取页码
            obj.p = p ? p : 1;        // 获取搜索框的内容
            obj.content = $('input[name=search]').val();        // 获取选择题型ID
            obj.to_type = $('.topic_type .on').attr('rel')        // 获取添加的学科领域
            obj.hotTag = '';
            $('.subjectAdd .hand').each(function() {
                obj.hotTag += $(this).attr('rel') + ',';
            })
            obj.hotTag = obj.hotTag.slice(0, -1);        // 异步传值
            $.post('/Topic/search', obj, function(json) {            var html = '';
                // 在弹出框里显示搜索出来的数据
                if (json['list']) {                for (var i = 0; i < json['list'].length; i++) {
                        html += '<div class="topicOption fl" rel="' + json['list'][i]['to_id'] + '" attr="' + json['list'][i]['to_type'] + '" owner="' + json['list'][i]['a_id'] + '">'
                                + '<p>'
                                + '<span>' + (i + 1) + '</span>'
                                + '<a class="editResource">编辑</a>'
                                + '</p>'
                                + '<div class="topicObj fl">'
                                + '<div class="ttitle">' + getIdByTopicType(json['list'][i]['to_type']) + '</div>'
                                + '<div class="tcontent">'
                                + json['list'][i]['to_title']
                                + '</div>'
                                + '<div class="tanswer">';
                        if (json['list'][i]['to_type'] == 1) {
                            html += syncSingle(syncCount, json['list'][i]['to_option'], json['list'][i]['to_answer']);
                        } else if (json['list'][i]['to_type'] == 2) {
                            html += syncMulti(json['list'][i]['to_option'], json['list'][i]['to_answer']);
                        } else if (json['list'][i]['to_type'] == 3) {
                            html += syncFill(json['list'][i]['to_option'], json['list'][i]['to_answer']);
                        } else if (json['list'][i]['to_type'] == 4) {
                            html += syncJudge(syncCount, json['list'][i]['to_option'], json['list'][i]['to_answer']);
                        } else {
                            html += '<label style="cursor: pointer;">' + syncShort(json['list'][i]['to_answer']) + '</label>';
                        }
                        html += '</div>'
                             +  '</div>'
                             +  '</div>'
                        syncCount++;
                    }
                } else {
                    html += '<div class="topicOption fl">暂无相关题目</div>';
                    json['page'] = '';
                }            // 显示内容
                $('#reslibrary').find('.resourceContent').html(html);            // 显示分页
                $('.page').html(json['page']);        }, 'json')
        }上面调用代码
    下面是json格式的数据{"page":"<a class='current' href='javascript:void(0);'>1<\/a><a href='javascript:getList(2);'>2<\/a><a href='javascript:getList(3);'>3<\/a><a href='javascript:getList(4);'>4<\/a><a href='javascript:getList(5);'>5<\/a>  <a href='javascript:getList(2);'>\u4e0b\u4e00\u9875<\/a> <a href='javascript:getList(19);'>\u6700\u540e\u4e00\u9875<\/a>  <a href=\"javascript:void(0);\">1\/19\u9875<\/a> <a href=\"javascript:void(0);\">92\u6761\u8bb0\u5f55<\/a>","list":[{"to_id":"92","a_id":"2","s_id":"1","to_title":"\u963f\u65af\u8482\u82ac\u6492\u53cd\u5bf9","to_type":"1","to_option":"0,1,2,3","to_answer":"[\"3\"]","to_note":"","to_peoples":"0","to_created":"1373682070","to_updated":"0","to_deleted":"0"},{"to_id":"91","a_id":"2","s_id":"1","to_title":"<p>\u591a\u5c11\u5929<\/p>","to_type":"1","to_option":"0,1,2,3","to_answer":"[\"2\"]","to_note":"","to_peoples":"0","to_created":"1373677212","to_updated":"1373677226","to_deleted":"0"},{"to_id":"90","a_id":"2","s_id":"1","to_title":"sadf","to_type":"1","to_option":"0,1,2,3","to_answer":"[\"1\"]","to_note":"","to_peoples":"0","to_created":"1373618621","to_updated":"0","to_deleted":"0"},{"to_id":"89","a_id":"2","s_id":"1","to_title":"<p>\u963f\u8428\u5fb7\u53d1\u5c04\u70b9\u53d1\u545c\u545c\u545c<\/p>","to_type":"3","to_option":"0","to_answer":"[\"\\u963f\\u8428\\u5fb7\\u53d1\\u751f\\u53d1\"]","to_note":"","to_peoples":"0","to_created":"1373608909","to_updated":"1373615683","to_deleted":"0"},{"to_id":"88","a_id":"2","s_id":"1","to_title":"<p>\u6d4b\u8bd5\u4f5c\u4e1a\u53d1\u5e03<\/p>","to_type":"4","to_option":"0,1","to_answer":"[\"0\"]","to_note":"","to_peoples":"0","to_created":"1373606127","to_updated":"1373615711","to_deleted":"0"}]}