是否可以访问HTML元素中的javascript变量 [英] Is it possible to access javascript variable in HTML element

查看:70
本文介绍了是否可以访问HTML元素中的javascript变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的视图中有锚标记。和一个在jquery脚本中有一些值的变量。

i需要像这样分配:< a href =/ Home / GoToAlbum?albumName = Name>



我尝试了什么:



i have anchor tag in in my view. and a variable with some value in jquery script.
i need to assign like this:<a href="/Home/GoToAlbum?albumName=Name">

What I have tried:

<pre><li class="item" style="height:334.03px;width:449.61px;">


                                @*<h2 class="post-title">Album 1</h2>
                                    <img src="@Url.Content(item)" alt="" class="images"  style="height:334.03px;width:449.61px;"/>*@

                                <figure class="overlay">
                                    <a href="/Home/GoToAlbum?albumName=">
                                        <div class="text-overlay caption">
                                            <div class="info">
                                                <h2 class="post-title">Album 1</h2>
                                                <div class="meta"><span class="count">10 Photos</span> <span class="date">5 Oct 2015</span> </div>
                                            </div>
                                        </div>
                                        <img src="@Url.Content(item)" alt="" class="images" style="height:334.03px;width:449.61px;" />
                                    </a>
                                </figure>
                            </li>










var imageSrc = $(this).attr('src');

           var splitContent = imageSrc.split('/');
           var albumName = splitContent[3];   // i need albumName to be pass as a parameter to above anchor tag

推荐答案

this )。attr(' src');

var splitContent = imageSrc.split(' / );
var albumName = splitContent [ 3 ]; // 我需要将albumName作为参数传递给上面的锚标记
(this).attr('src'); var splitContent = imageSrc.split('/'); var albumName = splitContent[3]; // i need albumName to be pass as a parameter to above anchor tag


在链接中添加ID



Add an id to the link

<a id="albumLink" href="/Home/GoToAlbum?albumName=">





并更新href





and update the href

var albumName = splitContent[3];


(#albumLink)。attr(href,
("#albumLink").attr("href",


这篇关于是否可以访问HTML元素中的javascript变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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