我也试图改变点击和颜色的价值。我可以通过js更改值但无法更改颜色。 这是我的Js代码
<td>
<input id="press5" name="press5" type="button" value="<?php echo $ro5[$_SESSION['dyy']] ?>"
onclick="return change(this);" onBlur="checkAvailability5()" class="btn btn-primary"/>
</td>
这是按钮:
public class ViewModelProductCategory
{
public int Id { get; set; }
public int? ParentId { get; set; }
public string Title { get; set; }
public int SortOrder { get; set; }
public IEnumerable<ViewModelProductCategory> Children { get; set; }
public List<ViewModelProduct> Products { get; set; }
public List<ViewModelProduct> OrphanProducts { get; set; }
}
请帮帮我。感谢。
答案 0 :(得分:1)
此代码将更改您的背景颜色,字体颜色和输入按钮的值。工作示例here。
<input type="button" value="P" onclick="return change(this);"/>
<script type="text/javascript">
function change( el )
{
if ( el.value === "P" ){
el.value = "B";
el.style.backgroundColor = "lightblue";
el.style.color = "blue";
}else{
el.value = "P";
el.style.backgroundColor = "lightpink";
el.style.color = "red";
}
}
</script>
答案 1 :(得分:0)
使用dom style
对象read here
function change( el )
{
if ( el.value === "P" ){
el.value = "A";
el.style.backgroundColor = "red";
} else {
el.value = "P";
el.style.backgroundColor = "blue";
}
}