当它在文字中时,如何在按钮上触发onclick命令 [英] How to fire onclick command on button when it is in literal

查看:67
本文介绍了当它在文字中时,如何在按钮上触发onclick命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

早上好朋友,

我用一个文字动态显示类似设计的代码。因为每个描述都有动态创建的按钮。所有内容都显示正确,但无法通过点击命令处理。

任何人都可以帮助我...



我的代码是< br $> b $ b

Good morning friends,
I take a one literal for dynamically display the code in similar design. In that each description has button which is dynamically create. All things display correctly but cant able to handle that on click command .
Can anyone help me please...

My code is

string str = "<div id=\"testDiv\"> ";
              if (dt.Rows.Count > 0)
              {
                  for (int i = 0; i < dt.Rows.Count; i++)
                  {
                      string JobTitle = dt.Rows[i]["Title"].ToString();
                      string Description = dt.Rows[i]["Description"].ToString();
                      string Company = dt.Rows[i]["EmployerName"].ToString();
                      string Location = dt.Rows[i]["Location"].ToString();
                      string AddedDate = Convert.ToDateTime(dt.Rows[i]["CreatedDate"].ToString()).ToString("D");
                      string Exp = dt.Rows[i]["MinExperience"].ToString() + " - " + dt.Rows[i]["MaxExperience"].ToString() + " Years";
                      string Salary = dt.Rows[i]["MinAnnualCTC"].ToString() + " - " + dt.Rows[i]["MaxAnnualCTC"].ToString() + " Lac P.A.";
                      string JobType = dt.Rows[i]["JobType"].ToString();
                      string JobID = dt.Rows[i]["JobID"].ToString();
                      string apply = "true";
                      if (Description.Length > 70)
                          Description = Description.Substring(0, 70).ToString() + " ... ";

                      str += "<div class=\"job_box\">" +
                            "    <div class=\"job_related_img\">" +
                            "      <img class=\"img-responsive\" src=\"../images/job_img.jpg\">" +
                            "   </div>" +
                            "   <div class=\"job_related_info\">" +
                            "     <div class=\"headtext\">" +
                            "   " + JobTitle + "</div>" +
                            "        <div>" +
                            "   <p>" +
                            "       " + Description + "</p>" +
                            "      </div>" +
                            "    <div class=\"comp_name\">" +
                            "   <p>" +
                            "       " + Company + "</p>" +
                            "       </div>" +
                            "      <div class=\"comp_location\">" +
                            "       <img src=\"../images/location.png\">" + Location + "" +
                            "         </div>" +
                            "        <div class=\"post_dt\">" +
                            "   <span>|</span> added " + AddedDate + "</div>" +
                            "      <div class=\"clearfix\">" +
                            "    </div>" +
                            "   <div class=\"set_bor\">" +
                            "    </div>" +
                            "   </div>" +
                            "  <div class=\"time_duration\">" +
                            "     <img src=\"../images/time.png\">" +
                            "     <span>" + JobType + "</span></div>" +
                            "<div class=\"time_durationhrs\">" +
                            "    <img src=\"../images/hrs.png\">" +
                            "   <span>" + Salary + "</span></div>" +
                            " <div class=\"app_vew_btn\">"+
                            "  <div> <span><font color=red>APPLIED</font></span></div><a class=\"log_in\" href=\"../JobDescription.aspx?id=" + JobID + "&apply=" + apply + "\">VIEW MORE</a></div>" +
                            "<div class=\"clearfix\">" +
                            "</div>" +

                  }
              }
              str += "    </div>";
              litBrowseAppliedJobs.Text = str;

          }



代替锚标记我想要按钮。


In place of anchor tag I want button.

推荐答案

尝试使用以下代码:



更改以下代码以添加按钮而不是锚标记:

Try with below code:

Change following code for adding button instead of anchor tag:
"<div> <span><font color="red">APPLIED</font></span></div>
<button onclick="myFunction(\"JobDescription.aspx?id=" + JobID + "&apply=" + apply + "\")">VIEW MORE</button>" +



添加javascript函数重定向:


Add javascript function to redirect:

<script type="text/javascript">
  function myFunction() {
    location.href = "http://www.cnn.com";
  }
</script>


这篇关于当它在文字中时,如何在按钮上触发onclick命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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