简体   繁体   English

使用输入文本更改按钮的边框半径

[英]Change the border-radius of a button with an input text

I have some issues and I don't know why. 我有一些问题,我不知道为什么。 I try to change the border-radius of a button with an input text but when I click on the submit button it don't work. 我尝试用输入文本更改按钮的边框半径,但是当我单击“提交”按钮时,它不起作用。 I have this : 我有这个 :

 $(document).ready(function(){ $("#submitBorderRadius").click(function(){ var x = $("#borderradiusSelect").val(); $("#testButton").css("borderRadius", x) }); }); 
 <button id="testButton">Test</button> <form> Border Radius : <input type="text" id="borderradiusSelect" value="0px"><br> <button id="submitBorderRadius">Submit</button> </form> 

Someone know what is the problem? 有人知道是什么问题吗?

When the "Submit" button is clicked, the page is getting reloaded, so you never get the opportunity to see the border radius value applied to the "Test" button. 单击“提交”按钮后,页面将重新加载,因此您将永远没有机会看到应用于“测试”按钮的边界半径值。

You can stop the page from reloading on click by using jQuery's preventDefault() method. 您可以使用jQuery的preventDefault()方法来阻止页面在单击时重新加载。

I've updated your code to show this in action: 我已经更新了您的代码以显示实际效果:

 $(document).ready(function(){ $("#submitBorderRadius").click(function(e){ e.preventDefault(); var x = $("#borderradiusSelect").val(); $("#testButton").css("borderRadius", x) }); }); 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button id="testButton">Test</button> <form> Border Radius : <input type="text" id="borderradiusSelect" value="0px"><br> <button id="submitBorderRadius">Submit</button> </form> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM