Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/434.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.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
Javascript js-单击问题时设置元素颜色_Javascript - Fatal编程技术网

Javascript js-单击问题时设置元素颜色

Javascript js-单击问题时设置元素颜色,javascript,Javascript,我试图设置元素的颜色。但是还没有成功。在这里,我想在点击时运行2个函数(addXXX,setcolor) 。$tweet['text'] 销售时点情报系统 不 负数 '; 将这两个函数放在一个单独的函数中,并调用该方法,而不是在“onclick”属性中运行两个方法调用 函数changeColor(参数) { addPOS(param.previousElementSibling.innerHTML+\'\'); $(#tweet).css(\'background-color\',\'red\

我试图设置元素的颜色。但是还没有成功。在这里,我想在点击时运行2个函数(addXXX,setcolor)

。$tweet['text']
销售时点情报系统
不
负数
';

将这两个函数放在一个单独的函数中,并调用该方法,而不是在“onclick”属性中运行两个方法调用


函数changeColor(参数)
{
addPOS(param.previousElementSibling.innerHTML+\'\');
$(#tweet).css(\'background-color\',\'red\');
}
等等。

使用Jquery

<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
 <div id="tweet">test</div>
 <input type="radio" name="pos" value="POS" onclick="$('#tweet').css('background-color', 'yellow');">

测试
如果使用普通javascript

<div id="tweet">test</div>
<input type="radio" name="pos" value="POS" onclick="document.getElementById('tweet').style.background = 'yellow'">
测试

如果要更改div onclick上的颜色。 试试这个

<div id="tweet"></div>
<input type="button" onclick="document.getElementById('div').style.backgroundColor='red'"/>


嘿,请缩进你的密码员。谢谢你的回复,但我的颜色没有改变。这就是为什么?我认为问题来自于背景色,我使用颜色一切都会成功。我需要设置背景色属性。我应该如何选择属性?您必须使用$(“#tweet”).css('background-color','yellow')。如果这不起作用,请共享“颜色”属性适用于您的代码。
<div id="tweet">test</div>
<input type="radio" name="pos" value="POS" onclick="document.getElementById('tweet').style.background = 'yellow'">
<div id="tweet"></div>
<input type="button" onclick="document.getElementById('div').style.backgroundColor='red'"/>