如何在单击事件中删除单选按钮的字体。 [英] How to strike out fonts of a radio button in its click event.

查看:66
本文介绍了如何在单击事件中删除单选按钮的字体。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hii,我正在开发一个项目,在这个项目中,我需要以字面方式进行字体删除。所以在这里我使用了两个单选按钮,当我点击Normal时,它的文本应该被抚摸出来,或者我点击异常它的字体应该被抚摸出来。这是我的代码,但它无法正常工作。



提前谢谢





<%@ Page Language =C#AutoEventWireup =trueCodeFile =test.aspx.csInherits =test%>



<!DOCTYPE html PUBLIC - // W3C // DTD XHTML 1.0 Transitional // ENhttp://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"> ;



< html xmlns =http://www.w3.org/1999/xhtml>

< head runat =server>

< title>< / title>

< script type =text / javascript>

function my_fun(j){

var chkbox =rdbVNormal+ j;

var chkbox1 =rdbVAbnormal+ j;

var my_span =my_span+ j;

var msg = chkbox ++ my_span;

if(document.getElementById(chkbox).checked){

document.getElementById(my_span).style.textDecoration = line-through';

返回true;

}



if(document.getElementById(chkbox1)。已检查){

document.getElementById(my_span).style.textDecoration ='line-through';

返回true;

}

else {

document.getElementById(my_span).style.textDecoration ='none';

返回false;

}

}

< / script>

< / head>

< body>

< form id =form1runat =server>

Hii, I'm working on a project and in this project I require to make the font strike out pro grammatically. So here I used two radio buttons and when I click on Normal its text should be stroked out and or I click on abnormal its font should be stroked out. Here Is my code for doing this but it does not work correctly.

Thanks in advance


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="test" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function my_fun(j) {
var chkbox = "rdbVNormal" + j;
var chkbox1 = "rdbVAbnormal" + j;
var my_span = "my_span" + j;
var msg = chkbox + " " + my_span;
if (document.getElementById(chkbox).checked) {
document.getElementById(my_span).style.textDecoration = 'line-through';
return true;
}

if (document.getElementById(chkbox1).checked) {
document.getElementById(my_span).style.textDecoration = 'line-through';
return true;
}
else {
document.getElementById(my_span).style.textDecoration = 'none';
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">



< asp:RadioButton ID =rdbVNormal runat =serverText =1GroupName =Eyevisiononclick =return my_fun(1); /> 正常

  / 

< asp:RadioButton ID =rdbVAbnormalrunat = serverText =2GroupName =Eyevisiononclick =return my_fun(2); /> 异常



< / form>

< / body>

< / html>


</form>
</body>
</html>

推荐答案

这可以在CSS中轻松完成:

This is easily done in CSS:
.someClass { text-decoration: line-through; }



您可以使用某些条件在代码隐藏中动态添加或删除CSS类(或者任何C#代码)或者在客户端使用Javascript(特别是使用jQuery很容易),或者两者兼而有之。



无需硬编码样式或任何其他与样式相关的属性,就像你一样;这被认为是一种非常糟糕的风格。



-SA


You can dynamically add or remove CSS classes in code-behind, using some condition (or any C# code) or do it on client side with Javascript (especially easy with jQuery), or both.

No need to hard-code style, or any other style-related attribute, into HTML elements as you do; this is considered to be a really poor style.

—SA


这篇关于如何在单击事件中删除单选按钮的字体。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆