选中框时显示按钮

我正在建立一个订阅偏好中心,我想在页面上显示一个按钮,如果订阅被选中(意味着他们已经选择接收这些类型的电子邮件)。

  • 如果未选中订阅,则会显示以下内容:

<input id="id_10139347" type="checkbox" name="id_10139347" >

  • 检查订阅时,它会显示:

<input id="id_10139347" type="checkbox" name="id_10139347" checked>

我如何在第二个要点中使用短语“已检查”,以便它在网页上显示一个按钮?


ibeautiful
浏览 91回答 3
3回答

慕娘9325324

我准备了一个简单的解决方案,当您单击复选框时,仅使用 CSS 来显示按钮。我希望这可以帮助你&nbsp; <label for="id_10139347"> CHECK BOX </label>&nbsp; &nbsp;<input class="suscriptionCheck" id="id_10139347" type="checkbox" name="id_10139347">&nbsp; &nbsp;<br/>&nbsp;<button>SOME BUTTON</button>button {&nbsp; display: none;}.suscriptionCheck:checked ~ button{&nbsp; display:block;&nbsp; padding: 14px;&nbsp;&nbsp;}https://codepen.io/r0binxp/pen/poygbXr

泛舟湖上清波郎朗

也许这会对你有所帮助。也有很多相同的问题得到了回答。$("#id_10139347").change(function() {&nbsp; &nbsp; if(this.checked) {&nbsp; &nbsp; &nbsp; &nbsp; //Do stuff&nbsp; &nbsp; }});

慕妹3242003

您可以执行以下操作:function displayButton(item) {&nbsp; if (item.checked == true) {&nbsp; &nbsp; document.getElementById("button").style.display = "block";&nbsp; } else {&nbsp; &nbsp; document.getElementById("button").style.display = "none";&nbsp; }}#button {&nbsp; display: none;}<input id="id_10139347" type="checkbox" name="id_10139347" onclick="displayButton(this)"><button id="button">Submit</button>displayButton()单击输入框时会触发该函数。如果选中输入,则显示按钮。否则不显示。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript