javascript - 使用文本框值更改按钮单击时的 CSS

标签 javascript jquery html css border

我正在尝试使用用户文本框答案中的值来更改图像的 CSS。我希望图像边框宽度在单击按钮时发生变化。这是我目前所拥有的。

$('#submit').click(function () {
        var bv = $('#border').val();
        $('#pic').css('border-width', bv);
        });
  • #submit 是按钮 id,#border 是文本框 id,#pic 是图片 id。 感谢所有建议。

最佳答案

试试这个

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function(){
        $('#submit').click(function () {
            var bv = $('#border').val();
            $('#pic').css('border-style', 'solid');//You should use this line of code to get your requirement
            $('#pic').css('border-width', bv);
        });
    });
</script>

<input type="text" id="border">
<input type="button" id="submit" value="submit">
<img src="http://wallruru.com/wp-content/uploads/2014/08/White-Background-56.jpg" id="pic"/>

关于javascript - 使用文本框值更改按钮单击时的 CSS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27008288/

相关文章:

javascript - CSS Z-index child above parent and div under parent

javascript - 避免循环 iframe

javascript - 如何在内部带有 "start"函数的 jQuery 函数中设置动画时间?

jquery - 如何在 jQuery 中使用嵌套的 foreach 循环?

jquery - 表头最大高度,不够横向展开

javascript - jQuery函数仅执行一次?

javascript - typescript 3 : JSX element type 'Component' does not have any construct or call signatures. [2604]

javascript - 基于属性的两个数组之间的不同对象 - lodash

javascript - 只要动画有效,就试图停止 jQuery 单击事件

jquery - 在基于百分比的设计中垂直居中文本?