Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/415.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 访客在输入文本字段中键入颜色代码时自动更改示例边框_Php_Javascript_Html_Css - Fatal编程技术网

Php 访客在输入文本字段中键入颜色代码时自动更改示例边框

Php 访客在输入文本字段中键入颜色代码时自动更改示例边框,php,javascript,html,css,Php,Javascript,Html,Css,我想知道当访问者在输入文本字段中输入颜色代码时,如何自动更改示例边框: 你有特别喜欢的边框颜色吗 input name="ContentInclude:borderspecs" type="text" maxlength="200" id="ContentInclude_borderspecs" tabindex="5" style="width:500px" 示例代码开头为:begin sample template最简单的解决方案: <input name="ContentIncl

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

你有特别喜欢的边框颜色吗

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

示例代码开头为:begin sample template

最简单的解决方案:

<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>

功能更改边框颜色(elem){
var template=document.getElementById('sampletemplate');
如果(elem.value.match(/^\#([\dabcdef]{3}}{124;[\ dabcdef]{6})$/i)){//十六进制代码
template.style.borderColor=元素值;
}
//如果要匹配其他可能的值,请执行更多操作
else{//重置为默认值
template.style.borderColor=null;//或“黑色”
}
}

//编辑后可更改模板预览的颜色
div#sampletemplate

应更改的示例边框是“您的示例广告模板”和围绕职位的边框以及一些文本,如“Lorem ipsum dolor sit amet,Concertetuer Adipising elit”。Mauris dui magna,ullamcorper et,…'这是部门样本模板吗?