有人可以帮我找到我的代码中的问题吗?我试图根据它的网址将 <span class="file-wrapper pointer">
<!-- <input type="file" name="sub_market_image_list" id="sub_market_image_list" onchange="previewImage(this,'previewId_1')"> -->
<span class="btn_upload" onclick="$('#profileFile').click();"><i class="fa fa-camera pointer"></i></span>
<input type="file" id="profileFile" name="profileFile" style="display:none;" file-model="profileImage" upload-after-changed="uploadProfile()">
</span>
设置为有效。但问题是加载后没有任何设置为活动状态。请告诉我如何做到这一点或任何其他方法来做到这一点?
注意 li
有空格。 $subj_descr
,COMPUTER PROGRAMMING 1
这里是ENGLISH 2
和li
找到的PHP代码。
a
这是我的js
<li data-popover="true" rel="popover" data-placement="right"><a href="#" data-target=".premium-menu" class="nav-header collapsed" data-toggle="collapse"><i class="fa fa-fw fa-book"></i> Lectures<i class="fa fa-collapse"></i></a></li>
<li><ul id="wa" class="premium-menu nav nav-list collapse in">
<?php
$sql ="SELECT enroll_ref FROM std_enrolled WHERE stud_no = '$stud_no'";
$result = mysqli_query($con, $sql);
while($row = mysqli_fetch_array($result)){
$enroll_ref = $row['enroll_ref'];
}
$sql3 ="SELECT DISTINCT subj_descr FROM subj_enrolled WHERE enroll_ref = '$enroll_ref'";
$results = mysqli_query($con, $sql3);
while($row = mysqli_fetch_array($results)){
$subj_descr = $row['subj_descr'];
?>
<li id="<?php echo $subj_descr; ?>" ><a href="viewlecture.php?subjdescr=<?php echo $subj_descr;?>"><span class="fa fa-caret-right"></span><?php echo ucwords(strtolower($subj_descr)); ?></a></li>
<?php
}
?>
</ul></li>
答案 0 :(得分:1)
您可以尝试使用以下代码:
$(document).ready(function() {
$(function(){
//location.search will give us query string i.e. part present after ? mark and ? itself which is nothing but ?subjdescr=COMPUTER PROGRAMMING 1
var current = decodeURIComponent(location.search); //decodeURIComponent to decode white space chars like %20 will get converted to white space
alert(current);
$('#wa li a').each(function(){
var $this = $(this);
alert(decodeURIComponent($this.attr('href')));
// if the current path is like this link, make it active
if(decodeURIComponent($this.attr('href')).indexOf(current) !== -1){
$this.closest("li").addClass('active'); //setting the active class to parent li and not to a tag
}
})
})
});
我想您需要将active
设置为li
代码而不是<a>
,所以只需通过$.closest()
注意:添加decodeURIComponent()
以避免字符串比较中的编码字符
答案 1 :(得分:0)
请尝试。
将lst[[ lst[[1]] ]]
替换为location.pathname
。
window.location.href
答案 2 :(得分:0)
您可以使用它来查找URL
中的文本 var my_url = "localhost/studentportal/viewlecture.php?subjdescr=COMPUTER%20PROGRAMMING%202";
var found_my_url = my_url.search("viewlecture.php");
var found_hashed = my_url.search("\\?");
if(found_my_url!=-1 && found_hashed!=-1)
{
var url_split = my_url.split("?");
var url_final = url_split[1].split("=");
if(url_final[1]=="COMPUTER%20PROGRAMMING%202")
{
alert("Found in the URL");
}
else
{
alert("NOT FOUND in the URL");
}
}