1

我想知道当访问者在输入文本字段中键入颜色代码时如何自动更改示例边框:

您有想要的特定边框颜色吗?

input name="ContentInclude:borderspecs" type="text" maxlength="200" id="ContentInclude_borderspecs" tabindex="5" style="width:500px"

https://advertiser.seek.com.au/advertisers/catalogue/templaterequest.ascx

示例代码以:开始示例模板开头

4

1 回答 1

0

最简单的解决方案:

<input name="ContentInclude:borderspecs" type="text" maxlength="200" 
    id="ContentInclude_borderspecs" tabindex="5" style="width:500px" 
    onkeyup="javascript:changeBorderColor(this);">

JS代码:

<script>
function changeBorderColor(elem){
    var template = document.getElementById('sampletemplate');
    if (elem.value.match(/^\#([\dabcdef]{3}|[\dabcdef]{6})$/i)) { // HEX code
        template.style.borderColor = elem.value;
    }
    // more else if to match other possible values
    else { // reset to default
        template.style.borderColor = null; // or "black"
    }
}
</script>

// 编辑所以它改变了模板预览的颜色div#sampletemplate

于 2012-09-03T09:05:30.090 回答