innerhtml()不读取javascript添加的css类属性

时间:2014-01-26 06:47:04

标签: c# jquery asp.net

我想读取html内容以及jquery从字符串变量中的代码后面添加的属性。

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

<!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>Untitled Page</title>
<style type="text/css">
#form1{width:60%; height:60%; margin:auto; background-color:White;}
html,body{height:100%; width:100%; background-color:Silver; font:100%;}
#sidePanel{height:50%; width:17%; float:left;}
.light{border:5px solid; border-radius:25px;}
</style>
<script src="Javascript/jquery-1.9.1.min.js" type="text/javascript"></script>
<script src="Javascript/jquery.corner.js" type="text/javascript"></script>

<script type="text/javascript">
    $(document).ready(function () {

    });

    function handleClick(light) {
$('#form1').addClass("light");
        $('#test').addClass("light");
        }
</script>
</head>
<body>
<div id="sidePanel" runat="server">
Residence Name<br />
<input type="radio" name="light" value="With Light" onclick="handleClick(this);"/>With     
Light<br/>
<input type="radio" name="light"value="Without Light"  
onclick="handleClick(this);"/>Without Light<br /><br />
Office Name Plate<br />
<input type="radio" name="light" runat="server" value="With Light Plate"  
onclick="handleClick(this);"/>With Light<br/>
<input type="radio" name="light" runat="server" value="Without Light Plate"   
onclick="handleClick(this);"/>Without Light<br /><br />
Table Top Name Plate<br />
<input type="radio" name="light" runat="server" value="With Light Table"  
onclick="handleClick(this);"/>Table Top<br/><br />

Cubical / Door Name Plate<br />
<input type="radio" name="light" runat="server" value="With Light Table"   
onclick="handleClick(this);"/>Cubicle / Door<br/>
<form runat="server">
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:Button ID="btnSave" runat="server" Text="Button" onclick="btnSave_Click" 
    style="height: 26px" />
    </form>
</div>
<div id="form1" runat="server">
<div id="test"></div>
</div>

</body>
</html>

以下是背后的代码:

protected void btnSave_Click(object sender, EventArgs e)
{
    string a=form1.InnerHtml;
}

form1.innerhtml在div标签中不包含 class =“light”属性

1 个答案:

答案 0 :(得分:0)

您是否尝试使用.CssClass属性访问该课程?

protected void btnSave_Click(object sender, EventArgs e)
{
    string a=form1.CssClass;
}