- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经使用自定义指令初始化了一个 jquery 插件。该插件按预期工作。然而,没有任何 AngularJS 特定代码在指令中不起作用
/*
Js steps
*/
app.directive('step', function () {
return {
link: function (scope, element, attrs) {
element.steps({
headerTag: "h3",
bodyTag: "section",
transitionEffect: "slideLeft",
stepsOrientation: "vertical"
});
}
}
});
//实现
<div step>
<h3>Services {{5+2}}</h3>
<section class="select_packages">
<div class="row">
<div class="col-md-12">
<h2 class="commonH2">1) Select Website Package</h2>
<p>What kind of website do you want?</p>
<hr/>
</div>
</div>
<div class="row">
<div class="col-md-4" ng-init="selectedClass =''" ng-class="{active_site: selectedClass === 'broucher'}" ng-click="selectedSite(1)">
<div class="quot_img">
<img src="img/man.jpg">
</div>
<div class="quot_details">
<h3 class="commonH3">Broucher Website</h3>
<p>
This package includes following items.
This package includes following itemsThis package includes following items.
This package includes following items This package includes following items.
This package includes following items
</p>
</div>
</div>
<div class="col-md-4" ng-class="{active_site: selectedClass === 'business_site'}" ng-click="selectedSite(2)" >
<div class="quot_img">
<img src="img/man.jpg">
</div>
<div class="quot_details">
<h3 class="commonH3">Business</h3>
<p>
This package includes following items.
This package includes following itemsThis package includes following items.
This package includes following items This package includes following items.
This package includes following items
</p>
</div>
</div>
<div class="col-md-4" ng-class="{active_site: selectedClass === 'ecommerce_site'}" ng-click="selectedSite(3)">
<div class="quot_img">
<img src="img/man.jpg">
</div>
<div class="quot_details">
<h3 class="commonH3">Ecommerce website</h3>
<p>
This package includes following items.
This package includes following itemsThis package includes following items.
This package includes following items This package includes following items.
This package includes following items
</p>
</div>
</div>
</div>
</section>
<h3>Additional Details</h3>
<section>
<p>Wonderful transition effects.</p>
</section>
<h3>Digital Marketing package</h3>
<section>
<p>The next and previous buttons help you to navigate through your content.</p>
</section>
</div>
</section>
例如:
ng-click 也不起作用。我是 angularjs 新手。
//website quotation page
app.controller("webQuotationController",function($scope, $http, $location, $rootScope, $window, $routeParams){
$scope.selectedVar = false;
$scope.showStep2 = false;
$scope.seoShow = false;
$scope.fb_advertising_budget_show = false;
$scope.showMarketing = false;
$scope.content_price_updated = 0;
$scope.design_price_updated = 0;
$scope.fullprice = 0;
$scope.nopage =0;
$scope.showContact = false;
$scope.onsite_updated = 0;
$scope.offsite_updated = 0;
$scope.ppc_updated = 0;
$scope.marketing_strategy_updated= 0;
$scope.marketing_email_updated = 0;
$scope.marketing_event_updated = 0;
var errorMsg = "";
var broucher_site_price = 500;
var business_site_price = 3000;
var ecommerce_site_price = 10000;
var design_price = 80; //per psd
var content_price = 40; //per page
var sitePrice = 0;
var numpage = 0;
// onsite price
var onsite = 1;
//offsite price per month
var offsite = 1;
//ppc price
var ppc = 1;
//marketing strategy price
var marketing_strategy = 1;
//email marketing price
var marketing_email = 1;
//event management price
var marketing_event = 1;
$scope.$on('$viewContentLoaded',function(){
console.log("web quotation page has loaded");
});
//detect which page it is
$scope.selectedSite = function(x)
{
//console.log("btn clicked");
//first check if selected site has been clicked because this is required
switch(x)
{
case 1:
$scope.selectedClass = "broucher";
sitePrice = broucher_site_price;
//default design price
$scope.nopage = 8;
console.log("Broucher site selected");
$('.site_type').remove();
$('.price-ul').append("<li class='site_type list-group-item'>Site: Broucher.</li>");
break;
case 2:
$scope.selectedClass = "business_site";
sitePrice = business_site_price;
$('.site_type').remove();
$('.price-ul').append("<li class='site_type list-group-item'>Site: business.</li>");
$scope.nopage = 15;
break;
case 3:
$scope.selectedClass = "ecommerce_site";
sitePrice = ecommerce_site_price;
$('.site_type').remove();
$('.price-ul').append("<li class='site_type list-group-item'>Site: Ecommerce.</li>");
$scope.nopage = 20;
break;
default:
$('.site_type').remove();
console.log("Nothing selected");
break;
}
}
$scope.marketing_smm_advert_selected = function()
{
//if selected then show the budget box
//console.log("budget should display");
if($scope.marketing_smm_advert == true)
{
$scope.fb_advertising_budget_show = true;
//console.log("budget should display");
}
else
{
$scope.fb_advertising_budget_show = false;
}
}
$scope.price = function()
{
if($scope.content == true)
{
//find out how many pages
numpage = $scope.nopage;
$scope.content_price_updated = content_price * numpage;
}else
{
$scope.content_price_updated = 0;
}
if($scope.design == true)
{
//find out how many pages
numpage = $scope.nopage;
$scope.design_price_updated = design_price * numpage;
}else
{
$scope.design_price_updated = 0;
}
$scope.fullprice =
sitePrice
+ $scope.content_price_updated
+ $scope.design_price_updated
+ $scope.onsite_updated
+ $scope.ppc_updated
+ $scope.offsite_updated
+ $scope.marketing_strategy_updated
+ $scope.marketing_email_updated
+ $scope.marketing_event_updated ;
return $scope.fullprice;
}
$scope.contentPrice = function()
{
if($scope.content == true)
{
//find out how many pages
numpage = $scope.nopage;
$scope.content_price_updated = content_price * numpage;
}else
{
$scope.content_price_updated = 0;
}
return $scope.content_price_updated;
}
$scope.designPrice = function()
{
if($scope.design == true)
{
//find out how many pages
numpage = $scope.nopage;
$scope.design_price_updated = design_price * numpage;
}else
{
$scope.design_price_updated = 0;
}
return $scope.design_price_updated;
}
// onsite price
$scope.onsitePrice = function()
{
console.log("onsite function hit");
if($scope.onsite == true)
{
$scope.onsite_updated = onsite;
console.log("onsite has been selected");
}
else
{
$scope.onsite_updated = 0;
console.log("Weird has been selected");
}
return $scope.onsite_updated;
}
//offsite price
$scope.offsitePrice = function()
{
if($scope.offsite == true)
{
$scope.offsite_updated = offsite;
}
else
{
$scope.offsite_updated = 0;
}
return $scope.offsite_updated;
}
//ppc price
$scope.ppcPrice = function()
{
if($scope.ppc == true)
{
$scope.ppc_updated = ppc;
}
else
{
$scope.ppc_updated = 0;
}
return $scope.ppc_updated;
}
//marketing strategy
$scope.marketing_strategyPrice = function()
{
if($scope.marketing_strategy == true)
{
$scope.marketing_strategy_updated = marketing_strategy;
}
else
{
$scope.marketing_strategy_updated = 0;
}
return $scope.marketing_strategy_updated;
}
//email marketing
$scope.marketing_emailPrice = function()
{
if($scope.marketing_email == true)
{
$scope.marketing_email_updated = marketing_email;
}
else
{
$scope.marketing_email_updated = 0;
}
return $scope.marketing_email_updated;
}
//marketing strategy
$scope.marketing_eventPrice = function()
{
if($scope.marketing_event == true)
{
$scope.marketing_event_updated = marketing_event;
console.log("marketign event price " + marketing_event );
}
else
{
$scope.marketing_event_updated = 0;
}
return $scope.marketing_event_updated;
}
//check if design is included
//get smm price
$scope.smm_package_price_get = function()
{
//first detect what has been selected
var selectedPack = $scope.smm_package;
switch(selectedPack)
{
case "1":
//if selected monthly
$scope.packageName = "monthly";
$scope.packagePrice = "150";
break;
case "2":
//if selected weekly
$scope.packageName = "weekly";
$scope.packagePrice = "400";
break;
case "3":
//if selected weekly
$scope.packageName = "daily";
$scope.packagePrice = "1200";
break;
default:
$scope.packageName = "Nothing has selected yet";
break;
}
}
//show contact form before submission
$scope.quotCompleted = function()
{
//check for validation
if(validationCheck() == true)
{
$scope.showContact = true;
console.log("quotation has been completed");
//$scope.scrollTo('show_contact');
$scope.errorMsg = "";
}else
{
//FIND responsible box
$scope.errorMsg = errorMsg;
}
}
//process additinal information when submit button is clicked
$scope.web_quot_submit = function()
{
//validation
if(validationCheck() == true)
{
$scope.formData = {};
//find out if all required field has been filled
//if valid
if(1 == 1) //or add different validation...in this case it is always true
{
//object to hold all info submitted
var additional_personal = {
//find list of item along with price
final_price : $scope.price(),
//find additioal details
other_info : $scope.additional,
dev_budget : $scope.budget,
exampleSite : $scope.exampleSite,
content: $scope.content,
content_price: $scope.contentPrice(),
design: $scope.design,
design_price: $scope.designPrice(),
page_num: $scope.nopage,
seo:$scope.seo,
onsite_seo:$scope.onsite,
onsite_seo_price: $scope.onsitePrice(),
offsite_seo: $scope.offsite,
offsite_seo_price: $scope.offsitePrice(),
seo_budget: $scope.seo_budget,
competetors: $scope.competetors,
ppc : $scope.ppc,
ppc_price: $scope.ppcPrice(),
marketing: $scope.marketing,
marketing_strategy: $scope.marketing_strategy,
marketing_strategy_price: $scope.marketing_strategyPrice(),
marketing_email: $scope.marketing_email,
marketing_email_price : $scope.marketing_emailPrice(),
marketing_event: $scope.marketing_event,
marketing_event_price: $scope.marketing_eventPrice(),
marketing_budget: $scope.marketing_budget,
marketing_smm_advert: $scope.marketing_smm_advert,
smm_advertisement_budget: $scope.smm_advertisement_budget,
smm_package: $scope.packagePrice,
smm_budget: $scope.smm_budget,
//find personal details
name :$scope.name,
email : $scope.email,
phone : $scope.phone
};
$scope.info = additional_personal;
console.log($scope.info);
$scope.formData = additional_personal;
// test... remove this once test is done...find out if submission is ok
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
url:'localhost/api/quotation/session',
type:'POST',
dataType:'json',
data: additional_personal,
success:function(data)
{
if(data){
console.log("session data :"+data.result);
if(data.result == true)
{
displayNotification();
}
else
{
alert("Something is wrong");
}
//insert into db
//alert("submitted : "+additional_personal);
console.log("data has been sent through ajax");
}else{
console.log("umm...the api was accessed but nothing was returned");
}
},
error:function(error)
{
console.log("there was an error with the api. Find a fallback");
}
});
//test ends
}else
{
//if not valid
console.log("not valid");
}
}
else
{
//validation error for email and name
alert("required Contact detail missing");
}
}
//little notification
var displayNotification = function()
{
var msg = "The quotation has been submitted";
$('#notification').html(msg);
}
//validation check
var validationCheck = function()
{
var validationVariable = true; //init variable
//check if a site has been selected
//if site_type class is present within dom that means it is pressed
if($scope.selectedVar == true)
{
if($('input[name="nopage"]').val() > 0 )
{
//if number of page input field has stuff init...then valid
validationVariable = true;
}
else
{
validationVariable = false;
errorMsg = " Number of pages required";
}
}
else
{
validationVariable = false;
errorMsg = " No site type has been selected";
}
//valid
console.log(errorMsg);
return validationVariable;
}
$scope.checkIfSelectedSeo = function()
{
if($scope.seo == true)
{
console.log("SEO SELECTED");
//display a box full of seo options
$scope.seoShow = true;
}
else
{
$scope.seoShow = false;
console.log("SEO not selected");
}
}
$scope.checkIfSelectedMarketing = function()
{
if($scope.marketing == true)
{
console.log("marketing SELECTED");
//display a box full of seo options
$scope.showMarketing = true;
}
else
{
$scope.showMarketing = false;
console.log("marketing not selected");
}
}
$scope.checkIfSelectedSocialMedia = function()
{
if($scope.smm == true)
{
console.log("smm SELECTED");
$scope.showSmm = true;
}
else
{
console.log("smm not SELECTED");
$scope.showSmm = false;
}
}
});
最佳答案
你是否为那段 HTML 设置了 Controller
<div ng-controller="webQuotationController">
<div step>
<!-- rest html here -->
</div>
</div>
<小时/>
<script>
app.directive('step', [function() {
return {
restrict: 'EA',
scope: {
stepChanging: '='
},
compile: function(element, attr) {
element.steps({
bodyTag: attr.bodyTag
});
return {
//pre-link
pre:function() {},
//post-link
post: function(scope, element) {
element.on('stepChanging', scope.stepChanging);
}
}
}
};
}]);
</script>
编辑:指令示例
关于javascript - ng-click 不适用于自定义指令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44720361/
将 .off 与 .click 结合使用有何用途或区别? $('#link').off('click').on('click',function(){}); 对比 $('#link').on('cli
我正在学习 javascript,并且我见过不止一种注册点击事件的方法: $(DOMelement).click(function() {}); $(DOMelement).on('click',fu
我习惯使用.click()和delegate('click') ,所以当我读到这两个在 jQuery 的最新版本中都被弃用时,我想我应该读一下它,但我有点摸不着头脑。 文档 here似乎表明这是 .l
我已经使用它们很长一段时间了,但大多数时候,我更喜欢较短的,但是,我只是想真正深入了解本质细节。我可能一直在创建有错误的代码,并且我不想在网络上贡献和传播懒惰完成的代码。 所以,告诉我: What a
我想实现类似在 Android 上点击 Instagram 中的帖子的功能(我认为在 iOS 上应该是相同的功能)。在 Instagram 中,如果有人点击照片,它会打开,双击,它会被喜欢,然后单击并
我的点击事件有问题。它运行 1 次。示例: 我有 3 页(1 2 3)。当我点击 2 时它起作用了。然后在第 3 页,它又可以工作了。但我再次点击 2 不起作用。该事件未触发。 $("div .top
我正在尝试这样做。在 jsfiddle 中:http://jsfiddle.net/QGGhW/2/ 但是在我点击 not now 之后,下一个文本输入就不再可点击了。 我该怎么做?是否有类似 .on
我想知道是否有任何情况下使用 .click(function {...}); 而不是 .live('click', function { ...});? 据我所知,实时选项似乎是一个更好的选择,因此我
我正在尝试在 Accordion 内部创建一个 Accordion ......并且我有点挣扎。 本质上,我有一个 div .applicant,单击它会添加一个 .expand 类,它将高度设置为
我可以使用一些帮助来调试这个: var factBody = jQuery(".fact__body"); jQuery(".fact").on("click", function() { j
如果我有一个用于 clicked 类的监听器,以及另一个用于 click-option-1、click-option-2 类的监听器,以及click-option-3,如何在我的 clicked 事件
下面的代码有什么区别吗? $('#whatever').on('click', function() { /* your code here */ }); 和 $('#whatever').
关闭。这个问题是opinion-based 。目前不接受答案。 想要改进这个问题吗?更新问题,以便 editing this post 可以用事实和引文来回答它。 . 已关闭 9 年前。 Improv
我不擅长 UI 设计,所以我使用 bootstrap 和 jquery 来帮助我一点。我正在尝试将 jQuery 事件绑定(bind)到导航栏,因此当用户单击导航栏上的 p 标签时,它应该触发单击事件
问题是,当我单击 delaccbut 按钮时,单击功能起作用并显示消息,但是当我单击 confdel 或 redel 按钮来自 click 函数,它不...为什么? HTML: Delete my
我想要完成的是“类似”的东西 $("button .toggleExcerpt) .toggle( function FIRST() { do first function..
function show1(){ $("#btn").click(show2()); window.alert(
我不明白为什么这不起作用。当我单击具有该类名的复选框时,clickId 被赋予值access-toggle-all,所以这没有意义(至少对我来说).. $(document).ready(functi
我有一个关于 click() 的复杂问题。我有 4 个按钮,分别命名为功能 1、功能 2、方法 1 和方法 2。 Function 1 Function 2 Method 1 Method 2 当单
最后,我认为这不是我特别需要解决的问题,但我不明白为什么会这样,这让我很困扰。 基本上,我有一些复选框,我只希望用户能够选择其中的一定数量。我正在使用下面的代码来实现该效果。 $j( function
我是一名优秀的程序员,十分优秀!