简体   繁体   English

使用颜色选择器更改所选动态文本框的文本颜色

[英]change text color of selected dynamic textbox using color picker

There are at most 15 text boxes in my page which is created on the click of a button. 单击按钮创建的页面中最多有15个文本框。 What I want is to change the text color of only the text-box which is "SELECTED"; 我想要的是仅更改“选择”文本框的文本颜色; the color of all the other text boxes should not change. 所有其他文本框的颜色不应更改。

Currently, I have a text color changer slider which changes the color of all the text boxes. 目前,我有一个文本颜色更改器滑块,它可以更改所有文本框的颜色。

Click here to download the source code. 单击此处下载源代码。

Please try this: 请尝试以下方法:
Include jscolor.js in your index file. 在索引文件中包含jscolor.js。 You can see more demo and download also from this link http://jscolor.com/try.php 您可以从此链接http://jscolor.com/try.php查看更多演示并下载

   <div>
         <?php
        or($i=0;$i<15;$i++){?>
            <div id="txt_add<?php echo $i; ?>" onclick="get_current_text(<?php echo $i; ?>);">
                            <div id="f<?php echo $i+1; ?>" class="bring_front"><span style="cursor:move"><input type="text" **class="box color"** placeholder="Sample text <?php echo $i+1; ?>" style="border:none; background:none; width:87px; margin-left:6px;" maxlength="10" onchange="set_color(<?php echo $i; ?>);"/></span></div>
               </div>
               <?php }?>                        
</div>

and put this code in javascript:    
 function set_color(txtid)
{
    $("#txt_add"+txtid+" input").css('color','#'+this.color);
    //document.getElementsByTagName('BODY')[0].style.backgroundColor = '#'+this.color
}
function get_current_text(id)
{
    $("#prod div input").css("background-color","white");
    $("#txt_add"+id+" input").css('background-color',"green");  $("#txt_add"+id+" input").css('color',"red");
}

Edit: 1)Change input class from box to box color 2) put this in input onchange="set_color();" 编辑:1)将输入类别从框更改为框颜色2)将其输入onchange =“ set_color();” 3) Put set_color function in your script 3)在脚本中放入set_color函数

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

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