Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在jquery post数据中查找元素并更新DOM_Javascript_Jquery_Html_Asp.net_Dom - Fatal编程技术网

Javascript 在jquery post数据中查找元素并更新DOM

Javascript 在jquery post数据中查找元素并更新DOM,javascript,jquery,html,asp.net,dom,Javascript,Jquery,Html,Asp.net,Dom,我有如下HTML标记: @if (ViewBag.Added != null) { if (ViewBag.Added == false) { <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="wholeBtn"> <a class="btn btn-app btnWatchList" style="min-widt

我有如下HTML标记:

@if (ViewBag.Added != null)
{
    if (ViewBag.Added == false)
    {                        
        <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="wholeBtn">
            <a class="btn btn-app btnWatchList" style="min-width:175px;margin:0;height:67px">
                <i class="fa fa-save"></i> Add to Watchlist
            </a>
        </div>
    }
    else if (ViewBag.Added)
    {
        <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="addedToWatchList">
            <h4>Added to watchlist</h4>
        </div>
    }
}
我想要的输出是显示html,它是:

else if (ViewBag.Added)
{
    <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="addedToWatchList">
        <h4>Added to watchlist</h4>
    </div>
}
else if(ViewBag.Added)
{
加入观察名单
}
我做错了什么


注意,当一切顺利时,我通过
returnview(“Index”)返回页面的整个HTML

好的,这就成功了:

  var header = $('<div />').append(data).find('#addedToWatchList').html();
                                 $('#wholeBtn').html(header).show();
                                 var l = document.getElementById('cancelButton');
                                 l.click();
var header=$('').append(data).find('#addedToWatchList').html();
$('#wholeBtn').html(header.show();
var l=document.getElementById('cancelButton');
l、 单击();
原来隐藏元素是一个坏主意,相反,我只是简单地更新了加载页面时满足if语句的原始元素,瞧,工作起来很有魅力

public ActionResult SaveWatchList(string comment, string rating, string competitor)
{
    if (comment == "" || rating == "" || competitor == "")
        return Json("AllFieldsRequired");
    else
    {
        var user = ctx.Users.Where(x => x.Email == User.Identity.Name).FirstOrDefault();

        var uwl = new UserWatchList() 
        { 
            Comment = comment, 
            Rating = Int32.Parse(rating), 
            Type = 0, 
            SellerFeedback = Int32.Parse(Session["score"].ToString()), 
            SentWord = competitor, 
            UserId = user.UserId 
        };

        ctx.UserWatchList.Add(uwl);
        ctx.SaveChanges();
        ViewBag.Added = true;

        return View("Index");
    }
}
else if (ViewBag.Added)
{
    <div class="col-lg-2 col-md-3 col-sm-12 col-xs-12" id="addedToWatchList">
        <h4>Added to watchlist</h4>
    </div>
}
  var header = $('<div />').append(data).find('#addedToWatchList').html();
                                 $('#wholeBtn').html(header).show();
                                 var l = document.getElementById('cancelButton');
                                 l.click();