如何从MVC中的patial视图使用jquery获取div的值 [英] How do I get the value of div using jquery from patial view in MVC
本文介绍了如何从MVC中的patial视图使用jquery获取div的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好程序员,
在我的项目中,我要求我在div中获取所有li标签id并在警报时显示它。我希望所有这些id都来自局部视图,只需点击一下按钮就可以在我的布局页面上调用它。
我尝试了什么:
所有li标签所在的页面
< big> < table>
< tr>
< td id =UserMenu>
< ul style =margin-left:590px>
< li id =menu01Userstyle =color:red; float:left; padding:5px; list-style:none>
< a href =##style =text-decoration:none>用户1< / a>
< / li>
< li id =menu02Userstyle =color:red; float:left; padding:5px; list-style:none>
< a href =/ Menu / UtilityMenustyle =text-decoration:none>用户2< / a>
< / li>
< li id =menu03Userstyle =color:red; float:left; padding:5px; list-style:none>
< a href =##style =text-decoration:none>用户3< / a>
< / li>
< / ul>
< / td>
< / tr>
< / table>< / big>
以下代码来自不同的文件(索引)
< input id =btnClicktype =buttonvalue =Processing/>
< div id =NestedMenustyle =display:none>< / div>
javaScript文件:
$(document).ready(function(){
var Ids = [];
$(#btnClick)。click(function(){
$ .ajax({
cache:false,
type:GET,
url:/ Menu / UserMenu,
成功:函数(数据){
调试器;
$(#NestedMenu)。innerHTML = data;
$ (#UserMenu)。find(li)。each(function(){
Ids.push($(this).attr(id));
alert(Ids);
});
},
错误:函数(数据){
alert(错误);
}});});
解决方案
(document).ready(function(){
var Ids = [];
( #btnClick)。单击(函数(){
.ajax({
cache:false,
type:GET,
url:/ Menu / UserMenu,
成功: function(data){
debugger;
Hello Programmers,
In my project I have a requirement that I want to get all the li tag id's inside a div and display it on alert. I want all those id's from a partial View and call it on my Layout page on a click of a button.
What I have tried:
The page in which all the li tag presents
<big> <table > <tr> <td id="UserMenu"> <ul style="margin-left:590px"> <li id="menu01User" style="color:red; float:left;padding:5px; list-style:none"> <a href="##" style="text-decoration:none">User 1</a> </li> <li id="menu02User" style="color:red; float:left;padding:5px; list-style:none"> <a href="/Menu/UtilityMenu" style="text-decoration:none">User 2</a> </li> <li id="menu03User" style="color:red;float:left;padding:5px; list-style:none"> <a href="##" style="text-decoration:none">User 3</a> </li> </ul> </td> </tr> </table></big>
The below code is from different file (index)
<input id="btnClick" type="button" value="Processing"/> <div id="NestedMenu" style="display:none"></div>
The javaScript file:
$(document).ready(function () { var Ids = []; $("#btnClick").click(function(){ $.ajax({ cache: false, type: "GET", url: "/Menu/UserMenu", success: function (data) { debugger; $("#NestedMenu").innerHTML=data; $("#UserMenu").find("li").each(function () { Ids.push($(this).attr("id")); alert(Ids); }); }, Error: function (data) { alert("Error"); } }); });解决方案(document).ready(function () { var Ids = [];
("#btnClick").click(function(){
.ajax({ cache: false, type: "GET", url: "/Menu/UserMenu", success: function (data) { debugger;
这篇关于如何从MVC中的patial视图使用jquery获取div的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文