gpt4 book ai didi

javascript - HTML 通过点击编辑按钮使 Div 可编辑

转载 作者:太空宇宙 更新时间:2023-11-03 18:39:31 24 4
gpt4 key购买 nike

当我点击左下角的编辑图标时,我试图让两个 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>

最佳答案

好吧,你可以这样做:

<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" 添加到您的按钮。

关于javascript - HTML 通过点击编辑按钮使 Div 可编辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17900706/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com