将id粘贴到href中

时间:2017-08-01 07:40:39

标签: javascript jquery html href

我有很多人。

# STUD_ID       MEAS  VALUE
#       1   LVEF(2D)    66
#       2   LVEF(2D)    54
#       2       IVSD    63
#       3  LVEF(M-M)    50
#       4   LVEF(2D)    71
#       4       PASP    55

我想要隐藏df %>% filter(MEAS == "LVEF(M-M)" | MEAS == "LVEF(2D)") %>% arrange(STUD_ID, MEAS) %>% group_by(STUD_ID, MEAS) %>% mutate(n = n()) %>% group_by(STUD_ID) %>% mutate(nd = n_distinct(MEAS)) %>% mutate(VALUE = case_when(nd == 2 ~ VALUE[which(MEAS == "LVEF(2D)")], nd == 1 & n > 1 ~ mean(VALUE), TRUE ~ VALUE)) %>% bind_rows( df %>% filter(MEAS != "LVEF(M-M)" & MEAS != "LVEF(2D)") )

如何将“id”粘贴到href

例如:

<a id="stream1" href="http://server/stream1/parameters">name_1</a>
<a id="stream2" href="http://server/stream2/parameters">name_2</a>
...
<a id="stream99" href="http://server/stream99/parameters">name_99</a>

使用

之类的东西
"http://server/stream99/parameters"

Javascript或jquery将链接并粘贴“id”。

或许我可以用某种方法来隐藏链接?

1 个答案:

答案 0 :(得分:2)

像这样 - 请注意,通过检查代码很容易解密。 或者,使用服务器重定向,只发送一些加密ID

&#13;
&#13;
$(function() {
  $(".stream").on("click", function(e) {
    e.preventDefault();
    location = "http://server/" + this.id + "/parameters";
  });
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<a id="stream1" class="stream" href="#">name_1</a><br>
<a id="stream2" class="stream" href="#">name_2</a><br>
<a id="stream3" class="stream" href="#">name_3</a><br>
<a id="stream4" class="stream" href="#">name_4</a><br>
&#13;
&#13;
&#13;