Div Show使用Webservice动态隐藏 [英] Div Show Hide Dynamically Using Webservice
本文介绍了Div Show使用Webservice动态隐藏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我创建了Div动态,一个Div在另一个内部,想要隐藏内容div点击外部div。我创建了div的id动态地通过webservice但是在jquery ajax中id没有得到,我无法隐藏内容div请给我一些链接或代码或任何其他类型的建议
从下面的评论复制的其他信息
MyWebservice.asmx.vb
< webmethod()> _
公共 功能 ChkBoxService() As 字符串
Dim sql As 字符串 = 从HallFoodingTrans中选择不同的FoodType HallCode ='HC1309000004'
Dim con As 新 SqlConnection(ConfigurationManager.AppSettings( myConnection))
Dim cmd 作为 新 SqlCommand (sql,con)
Dim da As ñ ew SqlDataAdapter(cmd)
Dim ds As 新 DataSet()
da.Fill(ds)
' var(id =id)
Dim lbl As 字符串 = lbl
< span class =code-keyword> Dim dividouter As String = dividouter
Dim dividinner 作为 字符串 = dividinner
Dim chkboxFoo dName 作为 字符串 = chkboxFoodName
Dim labelFoodRate As 字符串 = labelFoodRate
< span class =code-keyword> Dim txtInputFoodRate 作为 字符串 = txtInputFoodRate
Dim tablestring 作为 字符串 =
如果 ds.Tables( 0 )。Rows.Count<> 0 然后
Dim i 作为 整数 = 0
对于 每个 dr As DataRow 在 ds.Tables( 0 )。行
tablestring = tablestring + ( < div id ='dividouter& i& '>)
tablestring = tablestring + < label id ='lbl&我和我 '>& dr( FoodType)。ToString()& < / label>
Dim sql1 作为 字符串 = 选择不同的FoodName,从HallFoodingTrans评价FoodType ='& dr( FoodType)。ToString()& '和HallCode ='HC1309000004'
Dim con1 As 新 SqlConnection(ConfigurationManager.AppSettings( myConnection))
Dim cmd1 As 新 SqlCommand(sql1,con1)
Dim da1 作为 新 SqlDataAdapter(cmd1)
Dim ds1 As 新 DataTable()
da1.Fill(ds1)
Dim j As 整数 = 0
如果 ds1.Rows.Count> 0 然后
tablestring = tablestring +( < div id ='dividinner& i& & j& '>)
tablestring = tablestring + < table width ='100%'>< TR>< TD>首先柱头< / TD>< TD>第二个塔头和LT; / TD>< TD>第三列标题< / TD>< / TR>中跨度>
< span class =code-keyword> j< ds1.Rows.Count
使用 ds1.Rows(j)
tablestring = tablestring + < tr>< td>< input type ='checkbox'id ='chkboxFoodName&我和我 & j& '>& .Item( FoodName)。ToString& < / td>< td>< label id ='labelFoodRate&我和我 & j& '>& .Item( Rate)。ToString& < / td>< td>< input type ='text'id ='txtInputFoodRate&我和我 & j& '>< / td>< / tr>
j = j + 1
结束 使用
循环
tablestring = tablestring + < / table>
tablestring = tablestring + < / div>
结束 如果
tablestring = tablestring + < / div>
i + = 1
Next < /跨度>
结束 如果
返回 tablestring
结束 功能
< br $>
*************************
Default.aspx
< html xmlns = http://www.w3.org/1999/xhtml >
< head runat = server >
< script src = js / jquery-1.9.1.js 类型 = text / javascript > < / script >
< script type = text / javascript >
$( document )。ready( function (){
$ .ajax({
type: POST,
url: MyWebService.asmx / ChkBoxService,
data: {},
contentType: < span class =code-string> application / json; charset = utf-8,
dataType: json,
成功: function (数据){
var myData = data .d;
alert(myData);
$(' #chkwebservice' ).html(myData);
}
});
});
< / script >
< / head >
< body >
< 表格 id = form1 runat = 服务器 >
< div id = chkwebservice style = 背景色:绿色;高度:500px; >
< < span class =code-leadattribute> / div >
< ; / form >
< / body >
< / html >
解决方案
( document )。ready( function (){
.ajax({
type: POST ,
url: MyWebService.asmx / ChkBoxService,
data: {},
contentType: application / json; charset = utf-8,
dataType: json,
成功: function (数据){
var myData = data .d;
alert(myData);
(' # chkwebservice')。html(myData);
}
});
});
< / script >
< / head >
< body > ;
< 表格 id = form1 runat = server >
< div id = chkwebservice style = 背景色:绿色;高度:500px; >
< < span class =code-leadattribute> / div >
< ; / form >
< / body >
< / html >
I Created Div Dynamically,with One Div Inside Another and want to hide the content div on click of the outer div .I created Id of the div Dynamically through webservice but in the jquery ajax the id is not getting and i am unable to hide the content div please give me some links or code or any other kind of suggestion
additional information copied from comment below
MyWebservice.asmx.vb
<webmethod()> _
Public Function ChkBoxService() As String
Dim sql As String = "select distinct FoodType from HallFoodingTrans where HallCode= 'HC1309000004'"
Dim con As New SqlConnection(ConfigurationManager.AppSettings("myConnection"))
Dim cmd As New SqlCommand(sql, con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
'var(id = "id")
Dim lbl As String = "lbl"
Dim dividouter As String = "dividouter"
Dim dividinner As String = "dividinner"
Dim chkboxFoodName As String = "chkboxFoodName"
Dim labelFoodRate As String = "labelFoodRate"
Dim txtInputFoodRate As String = "txtInputFoodRate"
Dim tablestring As String = ""
If ds.Tables(0).Rows.Count <> 0 Then
Dim i As Integer = 0
For Each dr As DataRow In ds.Tables(0).Rows
tablestring = tablestring + ("<div id='dividouter" & i & "' >")
tablestring = tablestring + "<label id='lbl" & i & "' >" & dr("FoodType").ToString() & "</label> "
Dim sql1 As String = "select distinct FoodName,Rate from HallFoodingTrans where FoodType= '" & dr("FoodType").ToString() & "' and HallCode= 'HC1309000004 '"
Dim con1 As New SqlConnection(ConfigurationManager.AppSettings("myConnection"))
Dim cmd1 As New SqlCommand(sql1, con1)
Dim da1 As New SqlDataAdapter(cmd1)
Dim ds1 As New DataTable()
da1.Fill(ds1)
Dim j As Integer = 0
If ds1.Rows.Count > 0 Then
tablestring = tablestring + ("<div id='dividinner" & i & "" & j & "' >")
tablestring = tablestring + "<table width='100%'><tr><td>First Column Head</td><td>Second column Head</td><td>Third column Heading</td></tr>"
Do While j < ds1.Rows.Count
With ds1.Rows(j)
tablestring = tablestring + "<tr><td><input type='checkbox' id='chkboxFoodName" & i & "" & j & "' >" & .Item("FoodName").ToString & "</td><td><label id='labelFoodRate" & i & "" & j & "' >" & .Item("Rate").ToString & "</td><td><input type='text' id='txtInputFoodRate" & i & "" & j & "'></td></tr>"
j = j + 1
End With
Loop
tablestring = tablestring + "</table>"
tablestring = tablestring + "</div>"
End If
tablestring = tablestring + "</div>"
i += 1
Next
End If
Return tablestring
End Function
*************************
Default.aspx
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script src="js/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(document).ready(function(){
$.ajax({
type: "POST",
url: "MyWebService.asmx/ChkBoxService",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (data) {
var myData = data.d;
alert(myData);
$('#chkwebservice').html(myData);
}
});
});
</script>
</head>
<body>
<form id="form1" runat="server">
<div id="chkwebservice" style ="background-color:Green; height:500px;">
</div>
</form>
</body>
</html>
解决方案
(document).ready(function(){
.ajax({ type: "POST", url: "MyWebService.asmx/ChkBoxService", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (data) { var myData = data.d; alert(myData);
('#chkwebservice').html(myData); } }); }); </script> </head> <body> <form id="form1" runat="server"> <div id="chkwebservice" style ="background-color:Green; height:500px;"> </div> </form> </body> </html>
这篇关于Div Show使用Webservice动态隐藏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文