html - 如何在 jQuery Mobile 中动态更改输入字段的边框颜色

标签 html jquery-mobile cordova-2.0.0

我有一个输入字段,我想在其中提供验证我要更改占位符文本及其颜色,但我还想更改输入字段边框的颜色。 这是 html 的代码:

<input class="validate[required,custom[onlyLetterSp]] text-input" id="first_name" name="firstName" type="text" placeholder="First Name" maxlength="10" required>
    <input class="validate[required,custom[onlyLetterSp]] text-input" id="last_name" name="LastName" type="text" placeholder="Last Name" required>

这是用于验证和更改占位符颜色的 javascript 代码:

var defaultColor = 'BBBBBB';
var styleContent = 'input:-moz-placeholder {color: #' + defaultColor + ';} input::-webkit-input-placeholder {color: #' + defaultColor + ';}';
var styleBlock = '<style id="placeholder-style">' + styleContent + '</style>';
var randomColor='ff0000';
    // generate new styles and append to the placeholder style block
    styleContent = 'input:-moz-placeholder {color: #' + randomColor + ';} input::-webkit-input-placeholder {color: #' + randomColor + ';}'
     var colorchng='<style id="placeholder-style">' + styleContent + '</style>';
     if(first_name=="" || first_name=="First Name"){

        $("#first_name").append(colorchng);
        $("#first_name").attr("placeholder","First Name can not be blank");
    } if(last_name=="" || last_name=="Last Name"){
         $("#last_name").append(colorchng);
        $("#last_name").attr("placeholder","Last Name can not be blank");
    }else{
            alert("Data Entered");
    }

最佳答案

实现这个:

工作示例:http://jsfiddle.net/Gajotres/PMrDn/53/

HTML:

<input class="validate[required,custom[onlyLetterSp]] text-input" id="first_name" name="firstName" type="text" placeholder="First Name" maxlength="10"/>

Javascript:

$('#first_name').parent().css('border-color','red');

关于html - 如何在 jQuery Mobile 中动态更改输入字段的边框颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17896912/

相关文章:

html - 如何将此 CSS 转换为 webkit

javascript - "backbutton"事件不会触发

ios - PhoneGap 2.0 iOS 入门指南有bug?

html - vertical-align 没有将我的字段带到 DIV 的顶部

html - 为什么无法访问 CSS 选择器?

javascript - 禁用按钮上的页面背景提交点击

javascript - 使用 jQuery UI : How do I add an image to the dialog?

javascript - 使用 jQuery Mobile 在 pageshow 上加载函数并在离开页面时停止

jquery - 从 jquery 移动选择菜单中获取最宽的选项宽度

iphone - 使用phonegap 2.9.0在iphone中以编程方式在后台发送短信