我有3个引导模式,单独的textareas在textareas中显示相应模式的textarea中的复选框值。使用javascript或jquery将具有相同ID的多个文本区域内容复制到剪贴板
(我有一个jQuery捕获复选框值,并把它们在各自的texareas。所以它是工作的罚款)
但我在打开的onclick甚至每个模式将拷贝按钮指向函数将相应的textarea内容复制到剪贴板。但只有第一个模态值被复制。当我点击其他模式上的复制按钮时,这些值不会被复制。有什么,我失踪了。
textarea正在从div中捕获checkid
。所以textarea的id为checkid。复制按钮被激活以复制textarea内容。但是第一个模式的复制按钮不起作用,而不是其他模式。
function CopyNotes() {
var DataSet = document.getElementByID('checkid').value;
window.clipboardData.setData("TEXT", DataSet);
}
/* copying checkid */
$("#button1").click(function() { var p=$("#MaybeResolved #checkid"); $(p).html("Cx Verified " + '\n' + "The Following sports I play");
$.each($("input[name='Sport']:checked"), function() {
$(p).html($(p).html() + '\n' + $(this).val()); });
$(p).html($(p).html() + '\n --------------------------------------------------------------\n Thank you see you again. \n --------------------------------------------------------------');
}); \t
//Touch does not respond \t
$("#button2").click(function() { var p=$("#Resolved #checkid"); $(p).html("Cx Verified " + '\n' + "The Following sports I play");
$.each($("input[name='Sport']:checked"), function() {
$(p).html($(p).html() + '\n' + $(this).val()); });
$(p).html($(p).html() + '\n --------------------------------------------------------------\n Thank you see you again! \n --------------------------------------------------------------');
});
$("#button3").click(function() { var p=$("#Unresolved #checkid"); $(p).html("Cx Verified " + '\n' + "The Following sports I play");
$.each($("input[name='Sport1']:checked"), function() {
$(p).html($(p).html() + '\n' + $(this).val()); });
$(p).html($(p).html() + '\n --------------------------------------------------------------\n Thanks for contacting us.\n . \n --------------------------------------------------------------');
});
$("#button4").click(function() { var p=$("#MaybeResolved #checkid"); $(p).html("Cx Verified " + '\n' + "The Following sports I play:");
$.each($("input[name='Sport1']:checked"), function() {
$(p).html($(p).html() + '\n' + $(this).val()); });
$(p).html($(p).html() + '\n --------------------------------------------------------------\n Thank you see you again. \n --------------------------------------------------------------');
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<!-- bootstrap modal 1 -->
<textarea class="form-control" id="checkid" style="min-width: 100%" rows = "20">
</textarea>
<button class="btn btn-success btn-md" type="button" id="copy-button" data-toggle="tooltip" data-placement="button" title="Copy to Clipboard" onclick = "CopyNotes()">Copy</button>
<!-- bootstrap modal 2 -->
<textarea class="form-control" id="checkid" style="min-width: 100%" rows = "20">
</textarea>
<button class="btn btn-success btn-md" type="button" id="copy-button" data-toggle="tooltip" data-placement="button" title="Copy to Clipboard" onclick = "CopyNotes()">Copy</button>
<!-- bootstrap modal 3 -->
<textarea class="form-control" id="checkid" style="min-width: 100%" rows = "20">
</textarea>
<button class="btn btn-success btn-md" type="button" id="copy-button" data-toggle="tooltip" data-placement="button" title="Copy to Clipboard" onclick = "CopyNotes()">Copy</button>
<!---- Divs that get check box ids -->
<!--- div 1 -->
<form>
<h3>Select your favorite sports:</h3>
<label>
<input type="checkbox" value="football" name="sport"> Football</label>
<label>
<input type="checkbox" value="baseball" name="sport"> Baseball</label>
<label>
<input type="checkbox" value="cricket" name="sport"> Cricket</label>
<label>
<input type="checkbox" value="boxing" name="sport"> Boxing</label>
<label>
<input type="checkbox" value="racing" name="sport"> Racing</label>
<label>
<input type="checkbox" value="swimming" name="sport"> Swimming</label>
<br>
<button type="button">Get Values</button>
</form>
<button id = "button1" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" >I play these games</button>
<button id = "button2" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal2">I dont play these games</button>
<!--- div 2-->
<form>
<h3>Select your favorite sports:</h3>
<label>
<input type="checkbox" value="football" name="sport1"> Football</label>
<label>
<input type="checkbox" value="baseball" name="spor1t"> Baseball</label>
<label>
<input type="checkbox" value="cricket" name="sport1"> Cricket</label>
<label>
<input type="checkbox" value="boxing" name="sport1"> Boxing</label>
<label>
<input type="checkbox" value="racing" name="sport1"> Racing</label>
<label>
<input type="checkbox" value="swimming" name="sport1"> Swimming</label>
<br>
<button type="button">Get Values</button>
</form>
<button id = "button3" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal" >I play these games</button>
<button id = "button4" type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal2">I dont play these games</button>
<!-- div3--->
<!-- other div and so on.--->
<!--- the content is similar but also has addition checkboxes. -->
试图为文本区给出不同的ID名称 – Vaibhav
相同的ID内的同一页面是一个非常糟糕的主意! – FDavidov
我有3个按钮,每个div(有很多div),其中有复选框。有一个jquery捕获ID checkid下的值。然后是3个引导模式,根据点击的按钮显示值。 bs模态在它们中显示特定值。他们有一个复制按钮将内容复制到剪贴板。但复制按钮适用于拳头模式,而不适用于其他模式。 –