如何在图像滑块中放置不同的alt标签 [英] how to put varying alt tag in a image slider

查看:79
本文介绍了如何在图像滑块中放置不同的alt标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



i是asp.net的新手,我正在创建一个旅游网站。在这个网站上我有一个滑块,显示不同地方的图​​像,这些图像是从数据库动态检索的。这里我使用转发器来创建滑块,如下所示



Hi,
i am new to asp.net and i am creating a tourism website.In this website i have a slider which shows images of different places and this images are retrieved dynamically from database.Here i have used a repeater to create the slider as shown below

<section class="slider">
        <div class="flexslider">
          <ul class="slides">
           
  	    		<asp:Repeater ID="rptImages" runat="server">
        <ItemTemplate>
            <li>
  	    	    <img src='<%# Eval("image") %>' alt="" />
                <div class="myCaption"><%# Eval("place") %></div>
  	    		</li>
        </ItemTemplate>
    </asp:Repeater>
  	    		
          </ul>
        </div>
      </section>





代码落后



code behind

SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString);

       //======= Select Query.
       string cmdText = "SELECT place,image FROM tourdescription  where id='" + id + "' ORDER BY descid";

       //====== Providning information to SQL command object about which query to
       //====== execute and from where to get database connection information.
       SqlCommand cmd = new SqlCommand(cmdText, con);

       //===== To check current state of the connection object. If it is closed open the connection
       //===== to execute the insert query.
       if (con.State == ConnectionState.Closed)
       {
           con.Open();
       }

       //===== Execute Query and bind data to ListView.
       rptImages.DataSource = cmd.ExecuteReader();
       rptImages.DataBind();







这里的滑块有一个带有alt标签的图像的转发器。我想要使这个alt标签动态,如果图像滑块显示新德里的图像,那么alt标签应该是新的delhi。如果它显示agra然后alt标签应该是agra.Also它应该有助于在google图像中搜索agra时首先显示页面即帮助搜索引擎优化。任何人都可以告诉我一种方法。上帝保佑你。提前感谢你




here slider has repeater with an image having an alt tag.i want to make this alt tag dynamic that if image slider displays image of new delhi then alt tag should be new delhi.if it displays agra then alt tag should be agra.Also it should help in bringing page first while searching agra in google image ie help in search engine optimisation.Can anyone tell me a way to do that.God bless you.Thank you in advance

推荐答案

这是一个改变属性的JavaScript工作某些事件的HTML元素。如果要缩短代码,可以使用jQuery。



加载图片后,你可以添加这一行



This is however a job of JavaScript to change the attribute of the HTML element upon some event. You can use jQuery for this if you want to shorten the code.

Upon loading the image, you can add this line

// if the image's source attribute is new delhi
if(


' img')。attr(' src')== ' new_delhi.png'){
// 将alt属性设置为new delhi
('img').attr('src') == 'new_delhi.png') { // set the alt attribute to new delhi


' img')。attr(' alt'' 新德里);
// 否则
} else {
// 设置为agra。
('img').attr('alt', 'New Delhi'); // otherwise } else { // set to agra.


这篇关于如何在图像滑块中放置不同的alt标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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