1

当我单击左下角的编辑图标时,我试图使两个 DIV 都可编辑。我怎样才能做到这一点?

<li class="question" id="question2">

    <div class="question-header curves dense-shadows">

        What color is the sky? 
    </div>
    <div class="question-content dense-shadows">
        <ol type="A">
            <li><input type="radio" id="q2a1" name="question2" /> Red</li>
            <li><input type="radio" id="q2a2" name="question2" /> Green</li>
            <li><input type="radio" id="q2a3" name="question2" /> Blue</li>
            <li><input type="radio" id="q2a4" name="question2" /> Brown</li>
        </ol>
        <div style="text-align:right">
            <a href="#"><span style="margin-left:5px;"><img src="images/editbutton.png" 
                onmouseover="this.src='images/editbuttonhover.png'" onmouseout="this.src='images/editbutton.png'" title="Edit" alt="edit" /></span></a>
            <a href="#"><span style="margin-left:5px;"><img src="images/deletebutton.png" 
                onmouseover="this.src='images/deletebuttonhover.png'" onmouseout="this.src='images/deletebutton.png'" title="Delete" alt="delete"/></span></a>
        </div>
    </div>
</li>
4

2 回答 2

0

好吧,您的问题不清楚,但我会尝试猜测。如果你想让 div 可编辑,你可以用 contenteditable 标记它

所以要替换你的代码

 <a href="#"><span style="margin-left:5px;"><img src="images/editbutton.png" 
                onmouseover="this.src='images/editbuttonhover.png'" onmouseout="this.src='images/editbutton.png'" title="Edit" alt="edit" /></span></a>

<a href="javascript:void(0)" class="edit"><span style="margin-left:5px;"><img src="images/editbutton.png" 
                    onmouseover="this.src='images/editbuttonhover.png'" onmouseout="this.src='images/editbutton.png'" title="Edit" alt="edit" /></span></a>

然后添加脚本

<script>
    $("a.edit").click(function(){
       $("div.question-content").attr("contenteditable", "true");
    });
    </script>

请注意,我已添加类来链接并替换 HREF

这是我的示例http://jsfiddle.net/r9HTe/

于 2013-07-28T08:57:29.897 回答
0

好吧,你可以这样做:

<li class="question" id="question2">
    <div class="question-header curves dense-shadows">
        What color is the sky? 
    </div>
    <div class="question-content dense-shadows">
        <ol type="A">
            <li><input type="radio" id="q2a1" name="question2" /> Red</li>
            <li><input type="radio" id="q2a2" name="question2" /> Green</li>
            <li><input type="radio" id="q2a3" name="question2" /> Blue</li>
            <li><input type="radio" id="q2a4" name="question2" /> Brown</li>
        </ol>
        <div style="text-align:right">
            <a href="#" class="edit"><span style="margin-left:5px;"><img src="images/editbutton.png" 
                onmouseover="this.src='images/editbuttonhover.png'" onmouseout="this.src='images/editbutton.png'" title="Edit" alt="edit" /></span></a>
            <a href="#" class="delete"><span style="margin-left:5px;"><img src="images/deletebutton.png" 
                onmouseover="this.src='images/deletebuttonhover.png'" onmouseout="this.src='images/deletebutton.png'" title="Delete" alt="delete"/></span></a>
        </div>
    </div>
</li>

<script>    
$('a.edit').on('click',function(){
    $(this).closest('li').find('.question-header, .question-content').attr('contenteditable','true');
});
</script>

请注意,我已将class="edit"和添加class="delete"到您的按钮中。

于 2013-07-27T17:58:59.533 回答