Bootstran导航.active链接它没有将类.active添加到当前链接

时间:2016-01-18 21:23:47

标签: jquery twitter-bootstrap laravel-5.2

这可能是html:

<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
  <div class="container">
    <div class="navbar-header">
      <a class="navbar-brand" href="#">My Blog Site</a>
    </div>

    <div class="collapse navbar-collapse navbarCollapse">
        <ul class="nav navbar-nav">
            <li class="active"><a href="{{ route('blogs.index') }}">Blogs</a></li>
            <li><a href="{{ route('blogs.create') }}">Create</a></li>
        </ul>
    </div>
  </div>
</nav>

我有bootstrap.min.js但它没有效果的活动链接。然后我尝试用jquery做这个技巧:

$(document).ready(function() {
      $(".nav a").on("click", function(){
      $(".nav").find(".active").removeClass("active");
      $(this).parent().addClass("active");
   });
});

但是当我点击课程.active时会添加但是它会消失。我究竟做错了什么?谢谢。

1 个答案:

答案 0 :(得分:0)

我不知道但是在Laravel中var jsphotos = '@jsphotos'; var mockFiles = []; Dropzone.autoDiscover = false; var fileList = new Array; var fileListCounter = 0; var photoDropzone = new Dropzone('#photoDropzone', { url: 'importphotos.cshtml', paramName: "file", // The name that will be used to transfer the file maxFilesize: 5, // MB method: 'post', acceptedFiles: 'image/jpeg,image/pjpeg', dictInvalidFileType: 'Files uploaded must be type .jpg or .jpeg', init: function () { this.on("addedfile", function (file) { // remove size file.previewElement.querySelector('.dz-size').innerHTML = ''; // add custom button // Create the remove button var removeButton = Dropzone.createElement('<i class="fa fa-times-circle-o fa-3x removeButton"></i>'); // Capture the Dropzone instance as closure. var _this = this; // Listen to the click event removeButton.addEventListener("click", function (e) { // Make sure the button click doesn't submit the form: e.preventDefault(); e.stopPropagation(); // Remove the file preview. _this.removeFile(file); }); // Add the button to the file preview element. file.previewElement.appendChild(removeButton); }); this.on("success", function (file, serverFileName) { file.previewElement.querySelector('.dz-filename').innerHTML = '<span data-dz-name>'+serverFileName+'</span>'; }); this.on("removedfile", function (file) { //var rmvFile = ""; //for (f = 0; f < fileList.length; f++) { // if (fileList[f].fileName == file.name) { // rmvFile = fileList[f].serverFileName; // fileListCounter--; // } //} //if (rmvFile) { // $.ajax({ // url: "deletephoto.cshtml", // type: "POST", // data: { "fileList": rmvFile } // }); //} }); } }); $('#photoDropzone').sortable({ items: '.dz-preview', cursor: 'move', opacity: 0.5, containment: "parent", distance: 10, tolerance: 'pointer', sort: function (event, ui) { var $target = $(event.target); if (!/html|body/i.test($target.offsetParent()[0].tagName)) { var top = event.pageY - $target.offsetParent().offset().top - (ui.helper.outerHeight(true) / 2); ui.helper.css({ 'top': top + 'px' }); } }, update: function (e, ui) { // do what you want } }); if (jsphotos.length > 0) { var tmpSplit = jsphotos.split(','); for (i = 0; i < tmpSplit.length; i++) { if (tmpSplit[i].length > 0) { mockFiles.push(tmpSplit[i]); } } } for (i = 0; i < mockFiles.length; i++) { // Create the mock file: var mockFile = { name: mockFiles[i]}; // Call the default addedfile event handler photoDropzone.emit("addedfile", mockFile); photoDropzone.emit("success", mockFile, mockFile.name); // And optionally show the thumbnail of the file: //photoDropzone.emit("thumbnail", mockFile, '@Globals.tempUploadFolderURL' + mockFile.name); // Or if the file on your server is not yet in the right // size, you can let Dropzone download and resize it // callback and crossOrigin are optional. photoDropzone.createThumbnailFromUrl(mockFile, '@Globals.tempUploadFolderURL' + mockFile.name); // Make sure that there is no progress bar, etc... photoDropzone.emit("complete", mockFile); // If you use the maxFiles option, make sure you adjust it to the // correct amount: //var existingFileCount = 1; // The number of files already uploaded //Dropzone.options.maxFiles = myDropzone.options.maxFiles - existingFileCount; } //photoDropzone.files.length = mockFiles.length; 链接工作不同,它被称为活动状态所以我用jquery做的方式不起作用因为你正在处理<强>路由

然后我使用了来自 Dwight Watson 的优秀软件包 Active https://packagist.org/packages/watson/active

这就是Laravel的方式。